package settings;
import datamining.algorithms.Algorithm;
import datamining.miner.general.Frequency;
import datamining.miner.general.IntFrequency;
import datamining.sequence.Sequence;
import datamining.sequence.SequenceFactory;
import datamining.strategy.Strategy;
import de.parsemis.miner.environment.Statistics;
import utils.PropertiesConfig;

/** 
 * @author xujinghu, E-mail: jinghuxu@nudt.edu.cn
 * @date 2012-11-14 上午10:22:20 
 * @version 
 */
public class Settings<ItemType> {

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static void parse(String configFile, Settings set){
		set.configFile = configFile;
		set.minFreq = new IntFrequency(Integer.parseInt(PropertiesConfig.readData(configFile, "MIN_FREQUENCY")));
		set.maxFreq = new IntFrequency(Integer.parseInt(PropertiesConfig.readData(configFile, "MAX_FREQUENCY")));
		set.dataFile = PropertiesConfig.readData(configFile, "PREFIXSPAN_DATA");
		set.algoName = PropertiesConfig.readData(configFile, "ALGORITHM");
		set.logoFile = PropertiesConfig.readData(configFile, "LOGO_FILE");
		set.resourceDir = PropertiesConfig.readData(configFile, "RESOURCE_DIR");
		set.running = PropertiesConfig.readData(configFile, "RUNNING_STR");
		set.search_done = PropertiesConfig.readData(configFile, "SEARCH_DONE_STR");
		set.colored = PropertiesConfig.readData(configFile, "COLORED_STR");
		set.embeddingBased = Boolean.parseBoolean(PropertiesConfig.readData(configFile, "EMBEDDING_BASED_BOOL"));
		set.storeEmbeddings = set.embeddingBased || Boolean.parseBoolean(PropertiesConfig.readData(configFile, "EMBEDDING_STORE_BOOL"));
	}
	
	public String configFile = "conf/config.properties";
	public String resourceDir = "resource";
	public String dataFile = "";
	public String algoName= "prefixSpan";
	public Algorithm<ItemType> algorithm = null;
	public Strategy strategy = null;
	public SequenceFactory<ItemType> factory = null;
	public boolean naturalOrderedItemLabels = true;
	public boolean reverseOrderedItemLabels = false;
	public String logoFile = "logo.gif";
	public String running = "running";
	
	
	public String search_done = "search done";
	public String colored = "colored";
	public String NoDatabase = "No Database";
	public int threadCount = 1;
	public IntFrequency minFreq;
	public IntFrequency maxFreq;
	public boolean embeddingBased = false;
	public boolean storeEmbeddings = false;
	public Statistics stats;
	
	
	
	
	public Settings(String configFile){
		stats = new Statistics();
		parse(configFile,this);
	}
	
	public Settings(){
		stats = new Statistics();
	}
	
	@Override
	public String toString(){
		String str = "-----------------------------------------------------------------------------------------\n" +
				"参数设置（配置文件" + configFile + "）：\n" +
				"Minimum support is " + this.minFreq + "\n" +
				"EmbbedingBased is  " + this.embeddingBased + 
				"\n-----------------------------------------------------------------------------------------";
		
		return str;
	}
	
	/**
	 * STILL UNDER CONSTRUCTION
	 * 
	 * @param sequence
	 * @return the frequency of the given sequence
	 */
	public final Frequency getFrequency(final Sequence<ItemType> sequence) {
		return new IntFrequency(1); // TODO
	}
}
